package com.hsc.yalebao.secret;

import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

public class AESHelper
{
  private static final String CipherMode = "AES/ECB/PKCS5Padding";

  public static String byte2hex(byte[] paramArrayOfByte)
  {
    StringBuffer localStringBuffer = new StringBuffer(2 * paramArrayOfByte.length);
    for (int i = 0; ; i++)
    {
      if (i >= paramArrayOfByte.length)
        return localStringBuffer.toString().toUpperCase();
      String str = Integer.toHexString(0xFF & paramArrayOfByte[i]);
      if (str.length() == 1)
        localStringBuffer.append("0");
      localStringBuffer.append(str);
    }
  }

  private static SecretKeySpec createKey(String paramString)
  {
    if (paramString == null)
      paramString = "";
    StringBuffer localStringBuffer = new StringBuffer(32);
    localStringBuffer.append(paramString);
    while (true)
    {
      if (localStringBuffer.length() >= 32)
        if (localStringBuffer.length() > 32)
          localStringBuffer.setLength(32);
      try
      {
        byte[] arrayOfByte2 = localStringBuffer.toString().getBytes("UTF-8");
        arrayOfByte1 = arrayOfByte2;
        return new SecretKeySpec(arrayOfByte1, "AES");
        localStringBuffer.append("0");
      }
      catch (UnsupportedEncodingException localUnsupportedEncodingException)
      {
        while (true)
        {
          localUnsupportedEncodingException.printStackTrace();
          byte[] arrayOfByte1 = null;
        }
      }
    }
  }

  public static String decrypt(String paramString1, String paramString2)
  {
    try
    {
      byte[] arrayOfByte3 = hex2byte(paramString1);
      arrayOfByte1 = arrayOfByte3;
      arrayOfByte2 = decrypt(arrayOfByte1, paramString2);
      if (arrayOfByte2 == null)
        return null;
    }
    catch (Exception localException)
    {
      byte[] arrayOfByte2;
      while (true)
      {
        localException.printStackTrace();
        byte[] arrayOfByte1 = null;
      }
      try
      {
        String str = new String(arrayOfByte2, "UTF-8");
        return str;
      }
      catch (UnsupportedEncodingException localUnsupportedEncodingException)
      {
        localUnsupportedEncodingException.printStackTrace();
      }
    }
    return null;
  }

  public static byte[] decrypt(byte[] paramArrayOfByte, String paramString)
  {
    try
    {
      SecretKeySpec localSecretKeySpec = createKey(paramString);
      Cipher localCipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
      localCipher.init(2, localSecretKeySpec);
      byte[] arrayOfByte = localCipher.doFinal(paramArrayOfByte);
      return arrayOfByte;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
    return null;
  }

  public static String encrypt(String paramString1, String paramString2)
  {
    try
    {
      byte[] arrayOfByte2 = paramString1.getBytes("UTF-8");
      arrayOfByte1 = arrayOfByte2;
      return byte2hex(encrypt(arrayOfByte1, paramString2));
    }
    catch (Exception localException)
    {
      while (true)
      {
        localException.printStackTrace();
        byte[] arrayOfByte1 = null;
      }
    }
  }

  public static byte[] encrypt(byte[] paramArrayOfByte, String paramString)
  {
    try
    {
      SecretKeySpec localSecretKeySpec = createKey(paramString);
      System.out.println(localSecretKeySpec);
      Cipher localCipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
      localCipher.init(1, localSecretKeySpec);
      byte[] arrayOfByte = localCipher.doFinal(paramArrayOfByte);
      return arrayOfByte;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
    return null;
  }

  private static byte[] hex2byte(String paramString)
  {
    byte[] arrayOfByte;
    if ((paramString == null) || (paramString.length() < 2))
      arrayOfByte = new byte[0];
    while (true)
    {
      return arrayOfByte;
      String str = paramString.toLowerCase();
      int i = str.length() / 2;
      arrayOfByte = new byte[i];
      for (int j = 0; j < i; j++)
        arrayOfByte[j] = ((byte)(0xFF & Integer.parseInt(str.substring(j * 2, 2 + j * 2), 16)));
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.hsc.yalebao.secret.AESHelper
 * JD-Core Version:    0.6.2
 */